// const path = require('path');
const Koa = require('koa');
const koaBody = require('koa-body');
// const koaStatic = require('koa-static');
const session = require('koa-session');
const cors = require('koa-cors');
const router = require('./router');
const mongo = require('./model');
const auth = require('./authentication');

// const compression = require('koa-compress');
const app = new Koa();  //实例化koa
// app.use(compression());
app.keys = ['All', 'packages', 'installed' ]; //session signed key
app.use(cors({credentials:true}));
app.use(auth);  //自定义拦截器中间件
app.use(koaBody({ multipart: true }));//koa-body 需放在router前
app.use(router.routes()); //使用router
app.use(session({
        maxAge:1000*60*30,//cookie失效事件
        httpOnly:true,//只有服务器能够写cookie
        signed:true,//
        rolling:true,
        renew:true
},app)); //使用 koa-session
// app.use(koaStatic(path.join(__dirname)));
mongo(app); //连接数据库成功后监听端口80
